﻿using common.components;
using common.helpers;
using webserver.core;

namespace img.mgr.Apis
{
    public class ImgApiHelper : ApiHelperBase
    {
        public List<GetDirectoriesResponseItem> GetDirectories(GetDirectoriesRequest request)
        {
            var rsp = new ImgMgrHelper("img.mgr.db").GetDirectories(request);
            return rsp;
        }

        public TablePageResponse GetFiles(GetFilesRequest request)
        {
            var rsp = new ImgMgrHelper("img.mgr.db").GetFiles(request);
            return rsp;
        }

        private static bool _is_scan = false;

        public string Scan(ScanRequest request)
        {
            if (_is_scan)
            {
                return "正在扫描，请稍后再试";
            }

            _is_scan = true;
            TaskHelper.RunUseThread(() =>
            {
                new ImgMgrHelper("img.mgr.db").Scan(request);
                _is_scan = false;
            });
            return "开始扫描";
        }
    }
}
